package com.lvmama.common.result;

/**
 * Created by shenpeng on 2018/8/6.
 */
public class CodeMessage {
    private int code;

    private String message;

    //所有的异常在这里维护
    public static CodeMessage SUCCESS = new CodeMessage(0, "success");
    public static CodeMessage SERVER_ERROR = new CodeMessage(500100, "服务器错误！");
    public static CodeMessage BIND_ERROR = new CodeMessage(500101,"参数校验错误 : %s");
    public static CodeMessage DATA_ERROR = new CodeMessage(500102,"数据为空错误 : %s");

    //登录模块
    public static CodeMessage PASSWORD_EMPTY = new CodeMessage(500201, "密码不能为空！");
    public static CodeMessage ACCOUNT_NUM_EMPTY = new CodeMessage(500202, "账号不能为空！");

    //权限模块
    public static CodeMessage MENU_EMPTY = new CodeMessage(500201, "菜单为空！");

    public static CodeMessage ROLE_EXIST = new CodeMessage(500301, "角色已存在！");
    public static CodeMessage USER_EXIST = new CodeMessage(500401, "用户已存在！");
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public CodeMessage fillArgs(Object... args){
        int code = this.code;
        String message = String.format(this.message, args);
        return new CodeMessage(code, message);
    }

    private CodeMessage(int code, String message) {
        this.code = code;
        this.message = message;
    }
}
